Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start working on ability to have async_start_kernel in KernelManagers. #4126

Closed
wants to merge 6 commits into from

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Oct 20, 2018

I would like to have ability to have async function in there in
particular because I need to start a kernel via slurm, and I don not kow
ahead of time which node it is going to be schedule on.

So far most of the solutions there are hacky and require having ssh
tunnels, which I would like to avoid. As so far the start_kernel
function already setup and connect ports it requires to be made async,
or deeply change the API.

I went with creating and checking for a second 'async_start_kernel' on
super, as it is MultiKernelManager in jupyter_clienc, and changing
start_kernel to be a coroutine function would be a break of API.

I have a patch on jupyter_client that itself check whether prorper kernel
manager start_kernel function are coroutine functions or not.

In the long run this should allow to progressively migrate
jupyter_client to use and async start_kernel, but we can't yet as anyway
we still support 2.7 on jupyter-Client.

Note that gen.maybe_future in tornado is deprecated, and it is
recommended to check for results and yield unknown objects:

Deprecated since version 4.3: This function only handles Futures,
not other yieldable objects. Instead of maybe_future, check for the
non-future result types you expect (often just None), and yield
anything unknown

The kernel_id is a Unicode Traitlet so unless subclass overwite that
should be fine.

I would like to have ability to have async function in there in
particular because I need to start a kernel via slurm, and I don not kow
ahead of time which node it is going to be schedule on.

So far most of the solutions there are hacky and require having ssh
tunnels, which I would like to avoid. As so far the start_kernel
function already setup and connect ports it requires to be made async,
or deeply change the API.

I went with creating and checking for a second 'async_start_kernel' on
super, as it is MultiKernelManager in jupyter_clienc, and changing
`start_kernel` to be a coroutine function would be a break of API.

I have a patch on jupyter_client that itself check whether prorper kernel
manager start_kernel function are coroutine functions or not.

In the long run this should allow to progressively migrate
jupyter_client to use and async start_kernel, but we can't yet as anyway
we still support 2.7 on jupyter-Client.

Note that gen.maybe_future in tornado is deprecated, and it is
recommended to check for results and yield unknown objects:

    Deprecated since version 4.3: This function only handles Futures,
    not other yieldable objects. Instead of maybe_future, check for the
    non-future result types you expect (often just None), and yield
    anything unknown

The kernel_id is a Unicode Traitlet so unless subclass overwite that
should be fine.
)

sup = super(MappingKernelManager, self)
async_sk = getattr(sup, 'async_start_kernel', None)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async_sk = getattr(sup, 'async_start_kernel', None)
async_sk = getattr(sup, 'start_kernel_async', None)

sup = super(MappingKernelManager, self)
async_sk = getattr(sup, 'async_start_kernel', None)
if async_sk is not None:
res = super().async_start_kernel(**kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res = super().async_start_kernel(**kwargs)
res = super().start_kernel_async(**kwargs)

@Carreau Carreau force-pushed the async-kernelmanagers branch from a1e82fb to c16b4aa Compare October 31, 2018 20:23
if not isinstance(res, list):
kernels = res
else:
kernels = yield res
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these statements be reversed? Seems like a list is the end goal here and anything but that will likely be a future to yield. I apologize if my understanding is not correct and, if not, perhaps a comment would help.

@Carreau
Copy link
Member Author

Carreau commented Oct 31, 2018 via email

@blink1073
Copy link
Contributor

Closing as stale, thanks for experimenting with this @Carreau!

@blink1073 blink1073 closed this Jun 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants